using System;
using System.Collections.Generic;
using System.Linq;
namespace TemplateWeb.Controllers
{
	#region using
	using System.Web.Mvc;
	using TemplateWeb.Models.ViewModels;
	using TemplateWeb.Models;
	using TemplateWeb.Helpers;
	using System.Web.Security;
    using TemplateWeb.DTO;
	#endregion
	public partial class AdminController: BaseController
	{
		public ActionResult SelectHuongDan()
		{
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_HUONGDAN
			};
			return View(CreateViewModel(data));
		}



		public ActionResult DeleteHuongDan(int id, int page = 1)
		{
			var result = _repHuongDan.Delete(id);
			var data = new DataTransferViewModel
			{
				InfoText = result ? "Item has been deleted" : "Cannot delete item!",
				EnumViewModelType = EnumViewModel.ADMIN_HUONGDAN,
				CurrentPage = page
			};
			return View("SelectHuongDan", CreateViewModel(data));
		}

		public ActionResult DetailOfHuongDan(int id)
		{
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_DETAILOF_HUONGDAN,
				IntID = id
			};
			return View(CreateViewModel(data));
		}

		[ValidateInput(false)]
		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult UpdateHuongDan(FormCollection forms)
		{
			string id = forms.GetValues("HuongDan_ID")[0];
			string tenhuongdan = forms.GetValues("HuongDan_TenHuongDan")[0];
			string noidung = forms.GetValues("HuongDan_NoiDung")[0];
			var huongdan = _repHuongDan.SelectByID(int.Parse(id));
			huongdan.TenHuongDan = tenhuongdan;
			huongdan.NoiDung = noidung;
			var result = _repHuongDan.Update(huongdan);
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_DETAILOF_HUONGDAN,
				IntID = int.Parse(id),
				InfoText = result ? "Item has been updated" : "Cannot update this item"
			};
			return View("DetailOfHuongDan", CreateViewModel(data));
		}


		[ValidateInput(false)]
		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult InsertHuongDan(FormCollection forms)
		{
			string tenhuongdan = forms.GetValues("HuongDan_TenHuongDan")[0];
			string noidung = forms.GetValues("HuongDan_NoiDung")[0];
			var newItem = new HuongDanDTO
			{
				TenHuongDan = tenhuongdan,
				NoiDung = noidung
			};
			var result = _repHuongDan.Insert(newItem);
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_HUONGDAN,
				InfoText = result ? "New item has been added" : "Cannot insert new item"
			};
			return View("SelectHuongDan", CreateViewModel(data));
		}


	}
}